﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace ScrumSim
{
    public class AnimatedGameObject : GameObject
    {
        protected Dictionary<string, Animation> mAnimations;

        protected string mCurrentAnimation;

        public AnimatedGameObject(Game1 pGame, string pTexture)
            :base(pGame, pTexture)
        {
            mCurrentAnimation = "";
            mAnimations = new Dictionary<string, Animation>();
        }

        public override void Update(GameTime gameTime)
        {
            float lDelta = (float)gameTime.ElapsedGameTime.TotalSeconds;

            if (mCurrentAnimation != "")
                mAnimations[mCurrentAnimation].Update(lDelta);

            base.Update(gameTime);
        }

        //--------------------------------------------------

        public void AddAnimation(string pName, float pSpeed, int pNbFrames, Texture2D pSpritesheet, Rectangle pSubrect, bool pLoop = true)
        {
            mAnimations[pName] = new Animation(this, pName, pSpritesheet, pSubrect, pSpeed, pNbFrames, pLoop);
        }

        //--------------------------------------------------

        public void Play(string pAnim)
        {
            if (pAnim == mCurrentAnimation)
                return;

            mCurrentAnimation = pAnim;
            mAnimations[mCurrentAnimation].Play();
        }
    }
}
